#include <main.h>
unsigned int counter=0, value=12;

#INT_TIMER2
void  TIMER2_isr(void) 
{
	if(counter==0)
		{
			output_high(pin_c0);			// set the pin high
		}
	counter++;
	if (counter == value)
		{
			output_low(pin_c0);
		}
	if(counter==25)
		{
			counter=0;
		}
		
}

void indicator(void); 		
void rear_lights(void);	
void brake_lights(void);
void reverse_lights(void);
unsigned int read_keys(unsigned int Mask);

int a=20;

void main()
{
	setup_timer_2(T2_DIV_BY_16,249,10);		//2.0 ms overflow, 20.0 ms interrupt
	enable_interrupts(INT_TIMER2);
	enable_interrupts(GLOBAL);
	while(TRUE)
	{
		a=read_keys(0x07);
		switch(a)
		  {
		     case 0x01: 	indicator();
				break;
		     case 0x02: 	rear_lights();
				break;
		     case 0x04:		brake_lights();
				break;
		     case 0x08:		reverse_lights();
				break;
		     default :	break;
		     }
	  }
}

unsigned int read_keys(unsigned int Mask)
   {
		unsigned int val=0;
		
		if(kbhit()) val=getch(); 
		return val;
	}

void indicator(void)
{
  if (input(Pin_A0)) 
     {
	output_low(Pin_B0);
	delay_ms(500);
	output_high(Pin_B0);
	delay_ms(500);  
	
     }
}

void rear_lights(void)
{ 
   if(input(Pin_A1))
   {
      output_high(Pin_B1);
   }
} 

void brake_lights(void)
{ 
   if(input(Pin_A2))
   {
      output_high(Pin_B2);
   }
} 

void reverse_lights(void)
{ 
   if(input(Pin_A3))
   {
      output_high(Pin_B3);
   }
} 


#include <main.h>
unsigned int counter=0, value=12;

unsigned int read_keys(unsigned int Mask);		// read keys for use in a selection switch

void main()
{
	char a=0,f=0;


	while(TRUE)
	{
		while(f==0)
			{
				a=read_keys(0x07);
				if(a) f=1;
			}

		f=0;
		printf("%c",a);
		while(read_keys(0x07));

	}

}

unsigned int read_keys(unsigned int Mask)
	{
		unsigned int val=0;
		
		val=input_a();
		val=val & Mask;

		//lcd_gotoxy(1,2);

		//printf(lcd_putc,"Value = %2u",val);
		return val;

	}


